﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class AllMaintainRecords : System.Web.UI.Page
    {
        public int RecordsNumber { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindProduct();
            }
        }

        private void BindProduct()
        {           
            ApplicationProductService service = new ApplicationProductService();
            List<ApplicationProduct> products = service.GetProductByKeyWord(keyWordTextBox.Text);
            productGridView.DataSource = products;
            RecordsNumber = products.Count;
            service.GetProductByKeyWord(keyWordTextBox.Text);
            productGridView.DataBind();
        }

        protected void searchLinkButton_Click(object sender, EventArgs e)
        {
            BindProduct();
        }

        protected void resetLinkButton_Click(object sender, EventArgs e)
        {
            keyWordTextBox.Text = string.Empty;
            BindProduct();
        }

        protected void maintainProductGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            if (e.NewPageIndex >= 0 && e.NewPageIndex < productGridView.PageCount)
            {
                productGridView.PageIndex = e.NewPageIndex;
            }
            
            BindProduct();
        }

        protected void viewLinkButton_Click(object sender, EventArgs e)
        {
            hfProductID.Value = ((LinkButton)sender).CommandArgument;
            maintainRecordModalPopupExtender.Show();
            ClearWXForm();
            BindProductInfo();
        }

        protected void pageDDL_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList pageDDL = sender as DropDownList;
            productGridView.PageIndex = Convert.ToInt32(pageDDL.SelectedIndex);
            BindProduct();
        }

        private void BindProductInfo()
        {
            ApplicationProductService service = new ApplicationProductService();
            ApplicationProduct product = service.GetApplicationProductByID(long.Parse(hfProductID.Value));
            blxxTextBox.Text = product.BLXX;
            bzTextBox.Text = product.Remark;
            rmaMaintainLabel.Text = product.ApplicationForm.ApplicationCode;
            typeLabel.Text = product.ProductType.ProductTypeName;
            serialLabel.Text = product.ProductSerialNumber;
            versionNOLbl.Text = product.ProductVersionNumber;
            purchaseTimeLbl.Text = product.ProductPurchaseDateTime.Value.ToString("yyyy-MM-DD");
            wxwcrqLabel.Text = product.RepairCompleteDateTime != null ? Convert.ToDateTime(product.RepairCompleteDateTime).ToString("yyyy-MM-dd") : DateTime.Now.ToString("yyyy-MM-dd");

            /// Chen Pu: 2010-06-02 报价信息未能显示
            //if (product.Cost != null)
            //{
            //    bjLabel.Text = product.Cost.ToString();
            //}
            //else
            //{
            //    bjLabel.Text = "未报价";
            //}
            if (!product.QuatationForm.IsLoaded)
            {
                product.QuatationForm.Load();
            }
            if (product.QuatationForm != null && product.QuatationForm.Count > 0)
            {
                double cost = 0;
                int index = 1;
                foreach (QuatationForm quatation in product.QuatationForm)
                {
                    cost += quatation.Cost;

                    switch (index)
                    {
                        case 1:
                            blljTextBox1.Text = quatation.AccessoryName;
                            break;
                        case 2:
                            blljTextBox2.Text = quatation.AccessoryName;
                            break;
                        case 3:
                            blljTextBox3.Text = quatation.AccessoryName;
                            break;
                        case 4:
                            blljTextBox4.Text = quatation.AccessoryName;
                            break;
                        case 5:
                            blljTextBox5.Text = quatation.AccessoryName;
                            break;
                    }
                    index++;
                }
                bjLabel.Text = string.Format("总金额:{0}", cost);

                WXLJGridView.DataSource = product.QuatationForm;
                WXLJGridView.DataBind();
            }
            else
            {
                bjLabel.Text = "未报价";
            }

            if (!string.IsNullOrEmpty(product.ChangeType))
            {
                if (product.ChangeType.Equals("更换"))
                {
                    ghRadioButton.Checked = true;
                }
                if (product.ChangeType.Equals("替换"))
                {
                    thRadioButton.Checked = true;
                }
            }

            if (!string.IsNullOrEmpty(product.ReplaceProductSerialNumber))
            {
                thSerialNumberTextBox.Text = product.ReplaceProductSerialNumber;
            }

            if (!string.IsNullOrEmpty(product.ReplaceProductType))
            {
                thProductTypeTextBox.Text = product.ReplaceProductType;
            }

            if (!string.IsNullOrEmpty(product.ReplaceProductVersion))
            {
                versionDDL.SelectedValue = product.ReplaceProductVersion;
            }

            if (!string.IsNullOrEmpty(product.RepairAccessory))
            {
                InitialRepaireAccessory(product.RepairAccessory);
            }

            if (!string.IsNullOrEmpty(product.AccessoryPlace))
            {
                InitialAccessoryPlace(product.AccessoryPlace);
            }

            if (!string.IsNullOrEmpty(product.ReasonToProblem))
            {
                InitializeBLYY(product.ReasonToProblem);
            }

            if (!product.ProblemAnalyzeReference.IsLoaded)
            {
                product.ProblemAnalyzeReference.Load();
            }

            if (product.ProblemAnalyze != null)
            {
                InitializeProblemAnalyze(product.ProblemAnalyze);
            }

            InitialProductVersion();
        }

        private void ClearWXForm()
        {
            blxxTextBox.Text = "";
            blyyRadioButtonList1.ClearSelection();
            blyyRadioButtonList2.ClearSelection();
            blyyRadioButtonList3.ClearSelection();
            blyyRadioButtonList4.ClearSelection();
            blyyRadioButtonList5.ClearSelection();
            blljTextBox1.Text = "";
            blljTextBox2.Text = "";
            blljTextBox3.Text = "";
            blljTextBox4.Text = "";
            blljTextBox5.Text = "";
            ljwzTextBox1.Text = "";
            ljwzTextBox2.Text = "";
            ljwzTextBox3.Text = "";
            ljwzTextBox4.Text = "";
            ljwzTextBox5.Text = "";
            ghRadioButton.Checked = false;
            thRadioButton.Checked = false;
            thSerialNumberTextBox.Text = "";
            thProductTypeTextBox.Text = "";
            RadioButton1.Checked = false;
            RadioButton2.Checked = false;
            RadioButton3.Checked = false;
            RadioButton4.Checked = false;
            RadioButton5.Checked = false;
            RadioButton6.Checked = false;
            RadioButton7.Checked = false;
            RadioButton8.Checked = false;
            RadioButton9.Checked = false;
            RadioButton10.Checked = false;
            RadioButton11.Checked = false;
            RadioButton12.Checked = false;
            RadioButton13.Checked = false;
            bjLabel.Text = "";
            bzTextBox.Text = "";
            //Label1.Text = "";
        }

        private void InitializeProblemAnalyze(ProblemAnalyze problemAnalyze)
        {
            SetProblemAnalyzeA(problemAnalyze.A);
            SetProblemAnalyzeB(problemAnalyze.B);
            SetProblemAnalyzeC(problemAnalyze.C);
            SetProblemAnalyzeD(problemAnalyze.D);
            SetProblemAnalyzeE(problemAnalyze.E);
        }

        private void InitialProductVersion()
        {
            ProductClassService classService = new ProductClassService();
            versionDDL.DataSource = classService.GetVersions();
            versionDDL.DataTextField = "Name";
            versionDDL.DataValueField = "Name";
            versionDDL.DataBind();
        }

        private void InitialAccessoryPlace(string accessoryPlace)
        {
            string[] accessorys = accessoryPlace.Split(';');
            for (int i = 0; i < accessorys.Count(); i++)
            {
                switch (i)
                {
                    case 0:
                        ljwzTextBox1.Text = accessorys[i];
                        break;
                    case 1:
                        ljwzTextBox2.Text = accessorys[i];
                        break;
                    case 2:
                        ljwzTextBox3.Text = accessorys[i];
                        break;
                    case 3:
                        ljwzTextBox4.Text = accessorys[i];
                        break;
                    case 4:
                        ljwzTextBox5.Text = accessorys[i];
                        break;
                }
            }
        }

        private void InitializeBLYY(string blyy)
        {
            string[] blyyArray = blyy.Split(';');
            for (int i = 0; i < blyyArray.Count(); i++)
            {
                switch (i)
                {
                    case 0:
                        blyyRadioButtonList1.SelectedValue = blyyArray[i];
                        break;
                    case 1:
                        blyyRadioButtonList2.SelectedValue = blyyArray[i];
                        break;
                    case 2:
                        blyyRadioButtonList3.SelectedValue = blyyArray[i];
                        break;
                    case 3:
                        blyyRadioButtonList4.SelectedValue = blyyArray[i];
                        break;
                    case 4:
                        blyyRadioButtonList4.SelectedValue = blyyArray[i];
                        break;
                }
            }
        }

        private void InitialRepaireAccessory(string accessory)
        {
            string[] accessorys = accessory.Split(';');
            for (int i = 0; i < accessorys.Count(); i++)
            {
                switch (i)
                {
                    case 0:
                        blljTextBox1.Text = accessorys[i];
                        break;
                    case 1:
                        blljTextBox2.Text = accessorys[i];
                        break;
                    case 2:
                        blljTextBox3.Text = accessorys[i];
                        break;
                    case 3:
                        blljTextBox4.Text = accessorys[i];
                        break;
                    case 4:
                        blljTextBox5.Text = accessorys[i];
                        break;
                }
            }
        }

        protected void saveMaintainLinkButton_Click(object sender, EventArgs e)
        {
            try
            {
                ApplicationProductService service = new ApplicationProductService();
                ApplicationProduct product = service.GetSimpleApplicatonProductByID(long.Parse(hfProductID.Value));
                product.BLXX = blxxTextBox.Text;
                product.ReasonToProblem = getBLYY();
                product.RepairAccessory = getWXLJ();
                product.AccessoryPlace = getLJWZ();

                if (!string.IsNullOrEmpty(thSerialNumberTextBox.Text))
                {
                    product.ReplaceProductSerialNumber = thSerialNumberTextBox.Text;
                }
                if (!string.IsNullOrEmpty(thProductTypeTextBox.Text))
                {
                    product.ReplaceProductType = thProductTypeTextBox.Text;
                }
                if (versionDDL.SelectedIndex != 0)
                {
                    product.ReplaceProductVersion = versionDDL.SelectedValue;
                }
                if (thRadioButton.Checked)
                {
                    //product.ProductSerialNumber = thSerialNumberTextBox.Text;
                    product.ChangeType = "替换";
                }
                if (ghRadioButton.Checked)
                {
                    product.ChangeType = "更换";
                }
                product.Remark = bzTextBox.Text;
                //product.RepairCompleteDateTime = DateTime.Now; // Chen Pu: 2010-06-02 不能在这里保存维修完成时间
                if (!product.ProblemAnalyzeReference.IsLoaded)
                {
                    product.ProblemAnalyzeReference.Load();
                }
                if (product.ProblemAnalyze == null)
                {
                    product.ProblemAnalyze = new ProblemAnalyze();
                }
                product.ProblemAnalyze.A = getProblemAnalyzeA();
                product.ProblemAnalyze.B = getProblemAnalyzeB();
                product.ProblemAnalyze.C = getProblemAnalyzeC();
                product.ProblemAnalyze.D = getProblemAnalyzeD();
                product.ProblemAnalyze.E = getProblemAnalyzeE();

                string valisdtaResult = string.Empty;
                valisdtaResult = ValidateMaintain();
                if (string.IsNullOrEmpty(ValidateMaintain()))
                {
                    /// 客户要求维修记录填写保存时 不能修改维修状态，只有点击页面保存按钮后才可以修改
                    /// 因此将这块代码移到页面保存按钮点击事件里
                    //if (!product.UpgradeForm.IsLoaded)
                    //{
                    //    product.UpgradeForm.Load();
                    //}
                    //if (product.UpgradeForm.Count > 0 && product.UpgradeForm.FirstOrDefault().SendWay.Equals("平台"))
                    //{
                    //    UpgradeForm upgradeform = product.UpgradeForm.FirstOrDefault();
                    //    upgradeform.Status = "升级-完毕待发货";
                    //    product.Status = "升级-完毕待发货";
                    //}
                    //else
                    //{
                    //    product.Status = "维修完毕待发货";
                    //}
                    service.UpdateProduct(product);

                    //if (!product.ApplicationFormReference.IsLoaded)
                    //{
                    //    product.ApplicationFormReference.Load();
                    //}

                    //ApplicationService applicationService = new ApplicationService();
                    //if (applicationService.AllProductFinishRepair(product.ApplicationForm.ApplicationID))
                    //{
                    //    product.ApplicationForm.Status = "维修完毕待发货";
                    //}
                    maintainRecordModalPopupExtender.Hide();


                    //MsgLbl.Text = "维修记录已成功保存。";
                    //BindProduct();
                    //Response.Redirect(string.Format("FormNeedRepair.aspx?{0}={1}&IsEntireSubmit=False", Constants.QUERYSTR_APPLICATION_ID, Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
                }
                else
                {
                    Label1.Text = valisdtaResult;
                }
            }
            catch (Exception ex)
            {
                LogUtility.LogUtilityIntance.LogException(ex, "保存维修记录");
                //MsgLbl.Text = string.Format("系统错误:{0}", ex.Message);
            }
        }

        private string ValidateMaintain()
        {
            string result = string.Empty;
            if (string.IsNullOrEmpty(blxxTextBox.Text))
            {
                result += "请输入不良现象。";
            }
            if (ghRadioButton.Checked == false && thRadioButton.Checked == false)
            {
                if (RadioButton10.Checked == false)
                {
                    ///朱经理 2010-06-02 7:21:09
                    ///维修记录 当选择T05, retest ok ,P08 电源时不需要填写零件位置
                    //if (string.IsNullOrEmpty(getLJWZ()) &&
                    //    (blyyRadioButtonList1.SelectedIndex > 1 ||
                    //     blyyRadioButtonList2.SelectedIndex > 1 ||
                    //     blyyRadioButtonList3.SelectedIndex > 1 ||
                    //     blyyRadioButtonList4.SelectedIndex > 1))
                    //{
                    //    result += "请输入零件位置。";
                    //}
                    //if (string.IsNullOrEmpty(getBLYY()))
                    //{
                    //    result += "请输入不良原因。";
                    //}
                    if (string.IsNullOrEmpty(getWXLJ()))
                    {
                        result += "请输入维修零件。";
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(blljTextBox1.Text))
                        {
                            if (blyyRadioButtonList1.SelectedItem == null)
                            {
                                result += "请选择第1个零件的不良原因";
                            }
                            else if (string.IsNullOrEmpty(ljwzTextBox1.Text) && blyyRadioButtonList1.SelectedIndex != 2)
                            {
                                result += "请输入第1个零件的维修位置";
                            }
                        }

                        if (!string.IsNullOrEmpty(blljTextBox2.Text))
                        {
                            if (blyyRadioButtonList2.SelectedItem == null)
                            {
                                result += "请选择第2个零件的不良原因";
                            }
                            else if (string.IsNullOrEmpty(ljwzTextBox2.Text) && blyyRadioButtonList2.SelectedIndex != 2)
                            {
                                result += "请输入第2个零件的维修位置";
                            }
                        }

                        if (!string.IsNullOrEmpty(blljTextBox3.Text))
                        {
                            if (blyyRadioButtonList3.SelectedItem == null)
                            {
                                result += "请选择第3个零件的不良原因";
                            }
                            else if (string.IsNullOrEmpty(ljwzTextBox3.Text) && blyyRadioButtonList3.SelectedIndex != 2)
                            {
                                result += "请输入第3个零件的维修位置";
                            }
                        }

                        if (!string.IsNullOrEmpty(blljTextBox4.Text))
                        {
                            if (blyyRadioButtonList4.SelectedItem == null)
                            {
                                result += "请选择第4个零件的不良原因";
                            }
                            else if (string.IsNullOrEmpty(ljwzTextBox4.Text) && blyyRadioButtonList4.SelectedIndex != 2)
                            {
                                result += "请输入第4个零件的维修位置";
                            }
                        }

                        if (!string.IsNullOrEmpty(blljTextBox5.Text))
                        {
                            if (blyyRadioButtonList5.SelectedItem == null)
                            {
                                result += "请选择第5个零件的不良原因";
                            }
                            else if (string.IsNullOrEmpty(ljwzTextBox5.Text) && blyyRadioButtonList5.SelectedIndex != 2)
                            {
                                result += "请输入第5个零件的维修位置";
                            }
                        }
                    }

                    if (string.IsNullOrEmpty(getProblemAnalyzeA()) && string.IsNullOrEmpty(getProblemAnalyzeB()) && string.IsNullOrEmpty(getProblemAnalyzeC()) && string.IsNullOrEmpty(getProblemAnalyzeD()) && string.IsNullOrEmpty(getProblemAnalyzeE()))
                    {
                        result += "请输入故障分析";
                    }
                }
            }

            return result;
        }

        private string getLJWZ()
        {
            string ljwz = string.Empty;
            if (!string.IsNullOrEmpty(ljwzTextBox1.Text))
            {
                ljwz += ljwzTextBox1.Text;
            }
            if (!string.IsNullOrEmpty(ljwzTextBox2.Text))
            {
                if (!string.IsNullOrEmpty(ljwz))
                {
                    ljwz += ";";
                }
                ljwz += ljwzTextBox2.Text;
            }
            if (!string.IsNullOrEmpty(ljwzTextBox3.Text))
            {
                if (!string.IsNullOrEmpty(ljwz))
                {
                    ljwz += ";";
                }
                ljwz += ljwzTextBox3.Text;
            }
            if (!string.IsNullOrEmpty(ljwzTextBox4.Text))
            {
                if (!string.IsNullOrEmpty(ljwz))
                {
                    ljwz += ";";
                }
                ljwz += ljwzTextBox4.Text;
            }
            if (!string.IsNullOrEmpty(ljwzTextBox5.Text))
            {
                if (!string.IsNullOrEmpty(ljwz))
                {
                    ljwz += ";";
                }
                ljwz += ljwzTextBox5.Text;
            }
            return ljwz;
        }

        private string getWXLJ()
        {
            string wxlj = string.Empty;
            if (!string.IsNullOrEmpty(blljTextBox1.Text))
            {
                wxlj += blljTextBox1.Text;
            }
            if (!string.IsNullOrEmpty(blljTextBox2.Text))
            {
                if (!string.IsNullOrEmpty(wxlj))
                {
                    wxlj += ";";
                }

                wxlj += blljTextBox2.Text;
            }
            if (!string.IsNullOrEmpty(blljTextBox3.Text))
            {
                if (!string.IsNullOrEmpty(wxlj))
                {
                    wxlj += ";";
                }

                wxlj += blljTextBox3.Text;
            }
            if (!string.IsNullOrEmpty(blljTextBox4.Text))
            {
                if (!string.IsNullOrEmpty(wxlj))
                {
                    wxlj += ";";
                }

                wxlj += blljTextBox4.Text;
            }
            if (!string.IsNullOrEmpty(blljTextBox5.Text))
            {
                if (!string.IsNullOrEmpty(wxlj))
                {
                    wxlj += ";";
                }

                wxlj += blljTextBox5.Text;
            }

            return wxlj;
        }

        private string getBLYY()
        {
            string blyy = string.Empty;
            if (blyyRadioButtonList1.SelectedItem != null)
            {
                if (!string.IsNullOrEmpty(blyy))
                {
                    blyy += ";";
                }
                blyy += blyyRadioButtonList1.SelectedValue;
            }
            if (blyyRadioButtonList2.SelectedItem != null)
            {
                if (!string.IsNullOrEmpty(blyy))
                {
                    blyy += ";";
                }
                blyy += blyyRadioButtonList2.SelectedValue;
            }
            if (blyyRadioButtonList3.SelectedItem != null)
            {
                if (!string.IsNullOrEmpty(blyy))
                {
                    blyy += ";";
                }
                blyy += blyyRadioButtonList3.SelectedValue;
            }
            if (blyyRadioButtonList4.SelectedItem != null)
            {
                if (!string.IsNullOrEmpty(blyy))
                {
                    blyy += ";";
                }
                blyy += blyyRadioButtonList4.SelectedValue;
            }
            if (blyyRadioButtonList5.SelectedItem != null)
            {
                if (!string.IsNullOrEmpty(blyy))
                {
                    blyy += ";";
                }
                blyy += blyyRadioButtonList5.SelectedValue;
            }

            return blyy;
        }

        #region for problem analyze

        private string getProblemAnalyzeE()
        {
            string eStr = string.Empty;
            if (RadioButton11.Checked)
            {
                eStr = RadioButton11.Text;
            }
            return eStr;
        }

        private void SetProblemAnalyzeE(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Equals(RadioButton11.Text))
                {
                    RadioButton11.Checked = true;
                }
            }
        }

        private string getProblemAnalyzeD()
        {
            string dStr = string.Empty;
            if (RadioButton10.Checked)
            {
                dStr = RadioButton10.Text;
            }

            return dStr;
        }

        private void SetProblemAnalyzeD(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Equals(RadioButton10.Text))
                {
                    RadioButton10.Checked = true;
                }
            }
        }

        private string getProblemAnalyzeC()
        {
            string cStr = string.Empty;
            if (RadioButton9.Checked)
            {
                cStr = RadioButton9.Text;
            }
            else if (RadioButton8.Checked)
            {
                cStr = RadioButton8.Text;
            }
            else if (RadioButton13.Checked)
            {
                cStr = RadioButton13.Text;
            }

            return cStr;
        }

        private void SetProblemAnalyzeC(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Equals(RadioButton9.Text))
                {
                    RadioButton9.Checked = true;
                }
                if (value.Equals(RadioButton8.Text))
                {
                    RadioButton8.Checked = true;
                }
                if (value.Equals(RadioButton13.Text))
                {
                    RadioButton13.Checked = true;
                }
            }
        }

        private string getProblemAnalyzeB()
        {
            string bStr = string.Empty;
            if (RadioButton7.Checked)
            {
                bStr = RadioButton7.Text;
            }
            else if (RadioButton6.Checked)
            {
                bStr = RadioButton6.Text;
            }
            else if (RadioButton5.Checked)
            {
                bStr = RadioButton5.Text;
            }
            else if (RadioButton12.Checked)
            {
                bStr = RadioButton12.Text;
            }
            return bStr;
        }

        private void SetProblemAnalyzeB(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Equals(RadioButton5.Text))
                {
                    RadioButton5.Checked = true;
                }
                if (value.Equals(RadioButton6.Text))
                {
                    RadioButton6.Checked = true;
                }
                if (value.Equals(RadioButton7.Text))
                {
                    RadioButton7.Checked = true;
                }
                if (value.Equals(RadioButton12.Text))
                {
                    RadioButton12.Checked = true;
                }
            }
        }

        private string getProblemAnalyzeA()
        {
            string aStr = string.Empty;
            if (RadioButton4.Checked)
            {
                aStr = RadioButton4.Text;
            }
            else if (RadioButton3.Checked)
            {
                aStr = RadioButton3.Text;
            }
            else if (RadioButton2.Checked)
            {
                aStr = RadioButton2.Text;
            }
            else if (RadioButton1.Checked)
            {
                aStr = RadioButton1.Text;
            }
            return aStr;
        }

        private void SetProblemAnalyzeA(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Equals(RadioButton1.Text))
                {
                    RadioButton1.Checked = true;
                }
                if (value.Equals(RadioButton2.Text))
                {
                    RadioButton2.Checked = true;
                }
                if (value.Equals(RadioButton3.Text))
                {
                    RadioButton3.Checked = true;
                }
                if (value.Equals(RadioButton4.Text))
                {
                    RadioButton4.Checked = true;
                }
            }
        }

        #endregion

        protected void accessoryGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }            
        }

        protected void productGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                ((Label)e.Row.FindControl("IDLbl")).Text = (e.Row.RowIndex + 1).ToString();
            }
            if (e.Row.RowType == DataControlRowType.Pager)
            {
                DropDownList pageDDL = e.Row.FindControl("pageDDL") as DropDownList;
                for (int index = 1; index <= productGridView.PageCount; index++)
                {
                    pageDDL.Items.Add(index.ToString());
                }
                pageDDL.SelectedValue = (productGridView.PageIndex + 1).ToString();
            }
        }
        //protected void productGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        //{
        //    if (e.Row.DataItem != null)
        //    {
        //        ApplicationProduct product = (ApplicationProduct)e.Row.DataItem;
        //        if (!product.ApplicationFormReference.IsLoaded)
        //        {
        //            product.ApplicationFormReference.Load();
        //        }
        //        if (!product.ProductTypeReference.IsLoaded)
        //        {
        //            product.ProductTypeReference.Load();
        //        }
        //        if (!product.ProblemTypeReference.IsLoaded)
        //        {
        //            product.ProblemTypeReference.Load();
        //        }
        //    }
        //}
    }
}
